<%@page import="org.soenea.doitall.domain.model.group.IGroup"%>
<%@page import="org.soenea.doitall.domain.model.user.IUser"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Viewing Group</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/button.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/main.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/MainMenu.css" />

</head>
	<body>
		<c:if test="${!empty warning}">
			<b>Warning: </b> ${warning}<br />
		</c:if>
		<c:if test="${param['error']=='membernotfound'}">
			<b>Warning: </b> Could not find a member with that username.<br />
		</c:if>
		<c:if test="${param['error']=='memberalreadyingroup'}">
			<b>Warning: </b> That user is already part of a group and cannot be invited.<br />
		</c:if>
		<c:if test="${param['error']=='groupmodified'}">
			<b>Warning: </b> The group has been modified by another user. The updated group information is shown below.<br />
		</c:if>
		<div id="navbar"> 
			  <ul> 
			    <li><A HREF="javascript:javascript:history.go(-1)">Home</a></li> 
				<li><a href="${pageContext.request.contextPath}/servlet/app/browsegroups">View Groups</a></li> 
				<c:if test="${user.groupID>0}">
				<li><a href="${pageContext.request.contextPath}/servlet/app/viewgroup">My Group</a></li> 
				</c:if>
				<c:if test="${user.groupID==0}">
				<li><a href="${pageContext.request.contextPath}/servlet/app/browseinvite">View Invites</a></li>
				</c:if>
				<li><a href="${pageContext.request.contextPath}/servlet/app/logout">Logout</a></li> 
			  </ul> 
		</div>
		<div class="column">
			<h2>Group</h2>
			<hr />
			Group name: ${group.groupName}<br/>
			Description: ${group.description}<br/>
			<br/>
			<form method="POST" action="${pageContext.request.contextPath}/servlet/app/editgroup?version=${group.version}">	
				<label>New name: </label><input type="text" name="name" ><br/>
				<label>New description: </label><input type="text" name="description"><br/><br/>
				<input type="submit" value="Edit group" class="button" /><br/>
			</form>
			
			<br/>
			<a href="${pageContext.request.contextPath}/servlet/app/deletegroup" class="button">DELETE GROUP</a>
			<hr />
		</div>
		<div class="column">
			<h2>Members</h2>
			<hr />
			<table border="0">
			<tr><th>ID</th><th>Last Name</th><th>First Name</th><th>Username</th></tr>
			<c:forEach items="${users}" var="user">
			<tr><td>${user.id}</td><td>${user.lastName}</td><td>${user.firstName}</td><td>${user.userName}</td>
				<td>
				<c:if test="${user.id != self}">
				<a href="${pageContext.request.contextPath}/servlet/app/removemember/${user.id}" class="button">REMOVE</a>
				</c:if>
				</td>
			</tr>
			</c:forEach>
			</table>
			<br/>
			<hr />
		</div>
		<div class="column">
			<h2>Invite member</h2>
			<hr />
			<form method="POST" action="${pageContext.request.contextPath}/servlet/app/invitemember">	
				<label>Username: </label><input type="text" name="username" >
				<input type="submit" value="Invite" class="button" /><br/>
			</form>
			<hr />
		</div>
	</body>
</html>